#!/usr/bin/env python

import numpy
import pylab
from math import factorial
from matplotlib.font_manager import FontProperties as FP
#import nc_broadcast_probability as ncbp
import unicast_probability as ucp
import broadcast_probability as bcp


fp = FP()
fp.set_size('small')

### SPECIFICATIONS: ###
node_count = 10
packets_needed = 100
packet_range = 6000
succesrate_bc = 0.90
succesrate_uc = 0.90
#######################

packets = range(packet_range)


## Calculate values for probability for uc & bc:
y_uc = numpy.zeros(packet_range)
y_bc = numpy.zeros(packet_range)

for packet in packets:
	#y_nc[packet] = (ncbp.nc_probability_after_extra_transmissions(packets_needed, packet, succesrate_bc))**node_count
	y_uc[packet] = ucp.uc_probability_after_transmissions(packets_needed, packet, succesrate_uc, node_count)**node_count
	y_bc[packet] = bcp.bc_probability_after_transmissions(packets_needed, packet, succesrate_bc)**node_count



fig = pylab.figure(figsize=(10,5))
ax = fig.add_subplot(1,1,1)
ax.plot(packets[packets_needed:],y_uc[packets_needed:], 'k--')
ax.plot(packets[packets_needed:],y_bc[packets_needed:],'k-')
ax.set_ylim((0,1))
ax.set_yticks(numpy.arange(0,1.1,0.1))
ax.set_frame_on(False)

pylab.grid('on')

pylab.legend(["Unicast - "+str(100-succesrate_uc*100)+"% Packet Loss","Naive Broadcast (No Feedback) - "+str(100-succesrate_bc*100)+"% Packet Loss"], loc='lower right', prop=fp)

pylab.xlabel('Packet Transmissions')
pylab.ylabel('Probability of '+str(node_count)+' nodes having received \n all '+str(packets_needed)+' needed packets\n\n', ha='center')



pylab.savefig('netcod_plot2.eps')

# pylab.show()
